//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<XButton.h>
///	@path	~/src/gui/xgui/
///	@date	2008/10/30
///	@brief	.

#pragma once

#include "xeres.h"

#include "gui/IGuiControl.h"
#include "gui/style/style.h"
#include "gui/style/ext_style.h"
#include "gui/style/StyleText.h"
#include "gui/image/IBitmap.h"

namespace xeres {

	/*! 
		\class	XButton
		\brief	Base button encapsulation.
	*/
	class XButton : public IGuiControl
	{
	public:

		/// \ctor
		XButton( void );

		/// \ctor
		XButton( const WString& label , const Rect<int>& placement , function<void()> click = NULL );

		/// \dtor
		virtual ~XButton( void );

		DECL_IOBJECT_CLASS_DYNAMIC( XButton , IGuiControl );

	public:

		/// \name Button Methods
		//@{

		/// \brief	Set button text.
		void SetText( const WString& text );

		/// \brief	Get button text.
		const WString& GetText( void ) const { return m_label.GetString(); }

		/// \brief	Get style.
		RefWeak<CTextStyle> GetStyle( void );

		/// \brief	Set on click callback.
		void SetOnClick( function<void()> click ) { m_onClick = click; }

		//@}

		/// \name Message Passing
		//@{

		///	\brief	Process key input message.
		virtual HandleInput OnKeyInput( Updater& updater );

		///	\brief	Process mouse input message.
		virtual HandleInput OnMouseInput( Updater& updater );

		/// \brief	Call when close window.
		virtual void OnClose( void ) { m_onClick = NULL; }

		//@}

		/// \name Presentation Manipulation
		//@{

		/// \brief	Draw XGUI component to composition.
		virtual void Draw( Composition& composition );

		//@}

	private:

		//@ data
		bool				m_clicked;
		bool				m_spare[3];
		StyleText			m_label;
		function<void()>	m_onClick;
	};

	/*! 
		\class	XSimpleButton
		\brief	Clicked text & image button encapsulation.
	*/
	class XSimpleButton : public IGuiControl
	{
	public:

		/// \ctor
		XSimpleButton( void );

		/// \ctor
		XSimpleButton( const WString& label , RefWeak<IBitmap> image , const Pair<int>& pos );

		/// \dtor
		virtual ~XSimpleButton( void );

		DECL_IOBJECT_CLASS_DYNAMIC( XSimpleButton , IGuiControl );

	public:

		/// \name Button Methods
		//@{

		/// \brief	Call when mouse hover component.
		virtual void OnMouseHover( Updater& updater );

		/// \brief	Set size of component.
		virtual bool SetSize( const Pair<int>& size );

		/// \brief	Hit test.
		virtual bool HitTest( const Pair<int>& pt );

		/// \brief	Get text style.
		RefWeak<CTextStyle> GetStyle( void );

		/// \brief	Set button text.
		void SetText( const WString& text );

		/// \brief	Get button text.
		const WString& GetText( void ) const { return m_text.GetString(); }

		/// \brief	Set image.
		void SetImage( RefWeak<IBitmap> image );

		/// \brief	Get image.
		RefWeak<IBitmap> GetImage( void );

		/// \brief	Set on click callback.
		void SetOnClick( function<void()> click ) { m_onClick = click; }

		/// \brief	Set on hover callback.
		void SetOnHover( function<void()> hover ) { m_onHover = hover; }

		/// \brief	Set on return callback.
		void SetOnDefault( function<bool(bool)> on_default ) { m_onDefault = on_default; }

		//@}

		/// \name Message Passing
		//@{

		///	\brief	Process key input message.
		virtual HandleInput OnKeyInput( Updater& updater );

		///	\brief	Process mouse input message.
		virtual HandleInput OnMouseInput( Updater& updater );

		/// \brief	Call when close window.
		virtual void OnClose( void );

		//@}

		/// \name Presentation Manipulation
		//@{

		/// \brief	Draw XGUI component to composition.
		virtual void Draw( Composition& composition );

		//@}

	protected:

		//@ data
		bool				m_clicked;
		bool				m_spare[3];

		Ref<IBitmap>		m_image;
		StyleText			m_text;

		function<void()>		m_onClick;
		function<void()>		m_onHover;
		function<bool(bool)>	m_onDefault;
	};

	/*! 
		\class	XClickButton
		\brief
	*/
	class XClickButton : public XSimpleButton , public GuiSyleComp<CGuiStyle>
	{
	public:

		/// \ctor
		XClickButton( void );

		/// \ctor
		XClickButton( const WString& label , RefWeak<IBitmap> image , const Pair<int>& pos );

		/// \dtor
		virtual ~XClickButton( void );

		DECL_IOBJECT_CLASS_DYNAMIC( XClickButton , XSimpleButton );

	public:

		/// \name Button Methods
		//@{

		/// \brief	Get text style.
		RefWeak<CGuiStyle> GetStyle( void );

		/// \brief	Set size of component.
		virtual bool SetSize( const Pair<int>& size );

		//@}

		/// \name Message Passing
		//@{

		///	\brief	Process key input message.
		virtual HandleInput OnKeyInput( Updater& updater );

		///	\brief	Process mouse input message.
		virtual HandleInput OnMouseInput( Updater& updater );

		/// \brief	Call when control is about to enable or disable.
		virtual void OnEnable( bool enable );

		/// \brief	Call when focus is about to change.
		virtual void OnFocus( bool focusing );

		/// \brief	Call when mouse over control.
		virtual void OnMouseOver( bool hovering );

		//@}

		/// \name Presentation Manipulation
		//@{

		/// \brief	Draw XGUI component to composition.
		virtual void Draw( Composition& composition );

		//@}

	private:

		/// \brief	Change style call.
		void ChangeStyle( void );

		//@ data
	};

 } // namespace xeres
